const jwt = require('jsonwebtoken') ;

const {accept , expiresIn} = require('../config/config') ;

// 加密
exports.getToken = info => {
    return jwt.sign(info , accept , {expiresIn}) ;
}


// 解密
exports.parseToken = token => {
    return new Promise((resolve , reject) => {
        jwt.verify(token , accept , (err  ,data) => {
            if(err) {
                resolve({code : 0 , msg : 'token解析失败'})
            } else {
                resolve({code : 1 , msg : 'token解析成功'})
            }
        })
    })
}